package com.csun.cmny.provider.controller;

import com.csun.cmny.provider.model.dto.SendMessageRequest;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OpcMessageService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-11-12 14:39
 * @Description:
 */
@RestController
@RequestMapping(value = "/api")
public class CacApiController {

    @Autowired
    private OpcMessageService opcMessageService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    @PostMapping(value = "/sendMessageWithUser")
    public Wrapper sendMessageWithUser(@RequestBody SendMessageRequest sendMessageRequest) {

        opcMessageService.pushByUser(sendMessageRequest);

        //return WrapMapper.ok();
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null));
    }

    @PostMapping(value = "/sendMessageWithCode")
    public Wrapper sendMessageWithCode(@RequestBody SendMessageRequest sendMessageRequest) {

        opcMessageService.pushWithMsgCode(sendMessageRequest);

        //return WrapMapper.ok();
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null));
    }
}
